package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 聚合函数
 */
public class Demo7 {
    public static void main(String[] args) {
        //查看一共多少位老师?
        try (Connection conn = DBUtil.getConnection();){
            Statement statement = conn.createStatement();
            String sql = "SELECT COUNT(*) count,AVG(salary) avg_sal " +
                         "FROM teacher ";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int count = rs.getInt("count");
                double avgSal = rs.getDouble("avg_sal");
                System.out.println("一共:"+count+"人,平均工资为:"+avgSal);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
